package com.yztc.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;

import com.yztc.chunboapp.R;
import com.yztc.utils.BaseAcitivity;
import com.yztc.utils.ShareLog;

/**
 * Created by My on 2016/10/9.
 */
public class WebViewActivity extends BaseAcitivity {
    private ImageButton mIVBack,mIVShare;
    private TextView mTVTitle;
    private String mLink = null;
    private String mTitle = null;
    private WebView mWebView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        initView();
        //获取传递的数据
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        mLink = bundle.getString("link");
        mTitle = bundle.getString("title");
        //实现显示WebView的方法
        showWebView();
        //为backButton和shareButton设置监听
        setOnClickListener();
        //为标题设置数据
        setTitleData();
    }

    private void setTitleData() {
        mTVTitle.setText(mTitle);
    }

    private void setOnClickListener() {
        mIVBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mIVShare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new ShareLog(WebViewActivity.this,mLink);
            }
        });
    }


    private void showWebView() {
        mWebView.loadUrl(mLink);
        mWebView.setWebViewClient(new WebViewClient());
    }

    private void initView() {
        mWebView = (WebView) findViewById(R.id.wv_tiaozhuan);
        mIVBack = (ImageButton) findViewById(R.id.ibtn_back);
        mIVShare = (ImageButton) findViewById(R.id.ibtn_share);
        mTVTitle = (TextView) findViewById(R.id.tv_title);
    }


}
